function [pi, time, numiter]=PageRankPowerMethod(pi0,H,n,alpha,epsilon);

%Funcion tomada del libro Google's PageRank and Beyond. The science of
% search engine rankings. Autores: A.N. Langville y C.D.Meyer. (Pagina 42)

rowsumvector=ones(1,n)*H';
nonzerorows=find(rowsumvector);
zerorows=setdiff(1:n,nonzerorows); l=length(zerorows);
a=sparse(zerorows,ones(l,1), ones(l,1),n,1);

k=0;
residual=1;
pi=pi0;
tic;

while (residual >= epsilon)
  prevpi=pi;
  k = k+1;
  pi=alpha*pi*H + (alpha*(pi*a)+1-alpha)*((1/n)*ones(1,n));
  residual=norm(pi-prevpi,1);
  end
  numiter=k;
  time=toc;